package com.ruoyi.app.controller.project;

import com.ruoyi.app.business.project.ProjectLaborBusiness;
import com.ruoyi.app.config.annotation.OperationAuth;
import com.ruoyi.app.domain.project.labor.ProjectLaborApply;
import com.ruoyi.app.domain.project.labor.ProjectLaborFire;
import com.ruoyi.app.domain.project.labor.ProjectLaborHire;
import com.ruoyi.app.domain.project.labor.ProjectLaborInfo;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.project.query.ProjectLaborBaseQuery;
import com.ruoyi.service.user.enums.UserTypeEnum;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目员工管理
 *
 * @author Zane
 * @since 2025-10-10
 */
@RestController
@RequestMapping("/project/labor/")
public class ProjectLaborController {

  @Resource
  private ProjectLaborBusiness projectLaborBusiness;

  /**
   * 项目员工列表
   */
  @PostMapping("/listHired")
  public TableDataInfo<ProjectLaborInfo> listHired(
      @Validated @RequestBody ProjectLaborBaseQuery laborQuery) {
    CommonPageInfo<ProjectLaborInfo> laborPage = projectLaborBusiness.listHired(laborQuery);
    return CommonUtils.buildTableData(laborPage);
  }

  /**
   * 进组申请列表
   */
  @PostMapping("/listCouldHired")
  public TableDataInfo<ProjectLaborInfo> listCouldHired(
      @Validated @RequestBody ProjectLaborBaseQuery laborQuery) {
    CommonPageInfo<ProjectLaborInfo> laborPage = projectLaborBusiness.listCouldHired(laborQuery);
    return CommonUtils.buildTableData(laborPage);
  }

  /**
   * 招募
   */
  @PostMapping("/hire")
  public APIResult<Void> hire(@Validated @RequestBody ProjectLaborHire laborHire) {
    projectLaborBusiness.hire(laborHire);
    return APIResult.success();
  }

  /**
   * 进组申请
   */
  @OperationAuth(value = {UserTypeEnum.LABOR_USER}, laborHasBanedCheck = true)
  @PostMapping("/apply")
  public APIResult<Void> apply(@Validated @RequestBody ProjectLaborApply laborApply) {
    projectLaborBusiness.apply(laborApply);
    return APIResult.success();
  }

  /**
   * 离岗
   */
  @PostMapping("/fire")
  public APIResult<Void> fire(@Validated @RequestBody ProjectLaborFire laborFire) {
    projectLaborBusiness.fire(laborFire);
    return APIResult.success();
  }

}
